﻿using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using SIMS.Shared.DTO;
using SIMS.Shared.Models;
using SIMS.SqlSugarWebApi.Models;
using SIMS.SqlSugarWebApi.ServiceInterface;

namespace SIMS.SqlSugarWebApi.Controllers
{
    [Route("api/Classes/[action]")]
    [ApiController]
    public class ClassController : ControllerBase
    {
        private readonly IClassService _service;
        private readonly IMapper _mapper;

        public ClassController(IClassService service, IMapper mapper)
        {
            _service = service;
            _mapper = mapper;
        }

        [HttpPost]
        public async Task<IActionResult> AddClasses(ClassesDTO c)
        {
            var classes = _mapper.Map<Class>(c);
            var data = await _service.AddEntity(classes);
            var res = new ResponseResultModel() { data = data };
            return Ok(res);
        }

        [HttpDelete]
        public async Task<IActionResult> DeleteClasses(int id)
        {
            var data = await _service.DeleteEntity(id);
            var res = new ResponseResultModel() { data = data };
            return Ok(res);
        }

        [HttpGet]
        public async Task<IActionResult> GetClasses(int id)
        {
            var data = await _service.GetEntity(id);
            var res = new ResponseResultModel() { data = data };
            return Ok(res);
        }

        [HttpPut]
        public async Task<IActionResult> UpdateClasses(ClassesDTO c)
        {
            var classes = _mapper.Map<Class>(c);
            var data = await _service.UpdateEntity(classes);
            var res = new ResponseResultModel() { data = data };
            return Ok(res);
        }

        [HttpGet]
        public async Task<IActionResult> GetClassess(string? dept, string? grade, int pageNum, int pageSize)
        {
            var data = await _service.GetClassess(dept, grade, pageNum, pageSize);
            var res = new ResponseResultModel() { data = data };
            return Ok(res);
        }
    }
}
